"use strict";
cc._RF.push(module, '62095UZqIdBjb7Hlr9l4tbK', 'common');
// scripts/common.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.alert = exports.Client = exports.setUid = exports.setRoomId = exports.setUrl = exports.uid = void 0;
var log = console.log;
exports.uid = null;
var roomId = null;
var url = null;
function setUrl(Url) {
    url = Url;
}
exports.setUrl = setUrl;
function setRoomId(Roomid) {
    roomId = Roomid;
}
exports.setRoomId = setRoomId;
function setUid(Uid) {
    exports.uid = Uid;
}
exports.setUid = setUid;
var Client = /** @class */ (function () {
    function Client() {
    }
    Client.prototype.connect = function (task) {
        var _this = this;
        if (task === void 0) { task = null; }
        this.socket = new WebSocket(url);
        this.socket.onmessage = function (e) {
            var data = JSON.parse(e.data);
            log(data);
            switch (data.event) {
                case 'handOutCards':
                case 'grabCard':
                    _this.handOutCardsHandler(data);
                    break;
                case 'grabCardRes':
                case 'playOut':
                    _this.playOutHandler(data);
                    break;
                case 'gameOver':
                    _this.gameOverHandler(data);
                    break;
            }
            _this.receiveHandler(data);
        };
        this.socket.onopen = function (e) {
            if (task)
                _this.doTask(task);
        };
    };
    Client.get = function () {
        if (this._ins == null)
            this._ins = new Client();
        return this._ins;
    };
    Client.prototype.doTask = function (task, param) {
        if (param === void 0) { param = null; }
        var data = {
            uid: exports.uid, roomId: roomId, param: param
        };
        this.socket.send(JSON.stringify({
            task: task, data: data
        }));
    };
    Client.prototype.close = function () {
        this.socket.close();
    };
    return Client;
}());
exports.Client = Client;
var alert_1 = require("./alert");
function alert(text, parent) {
    cc.resources.load('alert', cc.Prefab, function (err, asset) {
        var ins = cc.instantiate(asset).getComponent(alert_1.default);
        ins.init(text, parent);
    });
}
exports.alert = alert;

cc._RF.pop();